<template>
  <div class="my_item">
    <van-list
      v-model="loading"
      :finished="finished"
      finished-text="没有更多了"
      @load="onLoad"
    >
      <div
        v-for="(item, index) in list"
        class="item"
        :class="proxy[status]"
        :key="index"
      >
        <div class="item__left">
          <div class="item__left-top">
            <span class="top__unit">¥</span>
            <span class="top__price">{{item.library.money}}</span>
          </div>
          <div class="item__left-bottom" v-if="item.good_id">
            指定商品使用
          </div>
        </div>
        <div class="item__right">
          <div class="item__right-top">
            <div class="top__title">{{item.library.name}}</div>
            <div class="top__des"></div>
          </div>
          <div class="item__right-bottom"><span>有效期{{item.end_time}}</span>
          <div class="transfer" @click="transfer(item)" v-if="item.status==1">
            我要转让
          </div>
          </div>
        </div>
      </div>
    </van-list>
  </div>
</template>
<script>
import { codeLists } from "@/api/myExaminatonGaper.js";
import  moment from "moment";
export default {
  props: {
    status: {
      type: Number,
    },
  },
  data() {
    return {
      loading: false,
      finished: false,
      list: [],
      proxy: {
        1: "canUse",
        2: "used",
        3: "outLimit",
      },
      pageInfo: {
        offset: 1,
      },
    };
  },
  components: {},
  methods: {
    async transfer(item){
      // console.log(item)
      this.$router.push(`/MyTransfer/${item.id}`)
    },
    async onLoad() {
      const res = await codeLists({
        status: this.status,
        offset: this.pageInfo.offset,
        limit: 10,
        user_id: weixin.getUserId(),
      });
      this.loading=false
      const arr=res.data.data.map(ele=>({...ele,end_time:moment(ele.end_time).format("YYYY-MM-DD")}))
      if (this.pageInfo.offset == 1) {
        this.list = [...arr];
      } else {
        this.list = [...this.list, ...arr];
      }
      this.pageInfo.offset++;
      if(arr.length<10){
          this.finished=true
      }
    },
  },
};
</script>
<style scoped>
.my_item {
  margin: 0 auto;
  width: 93.6vw;
  padding-top: 4vw;
}
.item {
  width: 93.6vw;
  height: 29.3vw;
  background-size:cover;
  margin-bottom: 4vw;
  display: flex;
}
.item.canUse{
  background-image: url('~@/assets/canUse.png');

}
.item.used{
  background-image: url('~@/assets/used.png');
  
}
.item.outLimit{
  background-image: url('~@/assets/outLimitTime.png');
  
}
.item__left{
  width: 29.3vw;
  height: 29.3vw;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
}
.item__left-top{

}
.top__unit{
  font-size: 4.5vw;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #FFFFFF;
}
.top__price{
  /*48px*/
  font-size: 6.4vw;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #FFFFFF;
  margin-top: 2.6vw;
}
.item__left-bottom{
  font-size: 3.2vw;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #FFFFFF;
}
.item__right{
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding-top: 3.2vw;
  padding-left: 3.2vw;
  padding-bottom: 4.53vw;
}
.item__right-bottom{
  font-size: 3.2vw;
  display: flex;
  justify-content: space-between;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #A1A1A1;
}
.top__title{
  font-size: 4.5vw;
  font-family: PingFangSC-Medium, PingFang SC;
  font-weight: 500;
  color: #333333;
}
.top__des{
  margin-top: 2.1vw;
  font-size: 3.3vw;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #777777;
}
.transfer{
  width: 18.1vw;
  height: 5.86vw;
  border-radius: 2.9vw;
  text-align: center;
  line-height: 5.86vw;
  border: 2px solid #FF8933;
  font-size: 3.2vw;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #FF8933;
}
</style>
